 <?php
/*
Plugin Name: 小工具
Description: 为主题添加小功能
Version: 1.2
Author: 徐文博
Author URI: http://geek-space.cn
*/

//主题颜色随机换
    function Bing_random_admin_color(){
        static $color;
    	if( isset( $color ) ) return $color;
    	$color = array_keys( $GLOBALS['_wp_admin_css_colors'] );
    	$color = $color[array_rand( $color )];
    	return $color;
    }
    add_filter( 'get_user_option_admin_color', 'Bing_random_admin_color' );



function example_remove_dashboard_widgets() {
    // Globalize the metaboxes array, this holds all the widgets for wp-admin
    global $wp_meta_boxes;
    // 以下这一行代码将删除 "快速发布" 模块
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
    // 以下这一行代码将删除 "引入链接" 模块
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
    // 以下这一行代码将删除 "插件" 模块
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
    // 以下这一行代码将删除 "近期评论" 模块
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
    // 以下这一行代码将删除 "近期草稿" 模块
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
    // 以下这一行代码将删除 "WordPress 开发日志" 模块
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
    // 以下这一行代码将删除 "其它 WordPress 新闻" 模块
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
    // 以下这一行代码将删除 "概况" 模块
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
}
add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );


function annointed_admin_bar_remove() {
        global $wp_admin_bar;
        /* Remove their stuff */
        $wp_admin_bar->remove_menu('wp-logo');
}
add_action('wp_before_admin_bar_render', 'annointed_admin_bar_remove', 0);

/**
 * WordPress 去除后台标题中的“—— WordPress”
 * http://www.wpdaxue.com/remove-wordpress-from-admin-title.html
 * 参考代码见 https://core.trac.wordpress.org/browser/tags/4.2.2/src/wp-admin/admin-header.php#L44
 */
add_filter('admin_title', 'wpdx_custom_admin_title', 10, 2);
function wpdx_custom_admin_title($admin_title, $title){
    return $title.' &lsaquo; '.get_bloginfo('name');
}

function change_footer_version() {return '';}
add_filter( 'update_footer', 'change_footer_version', 9999);
//小工具运行PHP
add_filter('widget_text', 'php_text', 99);
function php_text($text) {
if (strpos($text, '<' . '?') !== false) {
ob_start();
eval('?' . '>' . $text);
$text = ob_get_contents();
ob_end_clean();
}
return $text;
}

//网页加载时间 By 阿e Blog http://www.aeblog.me/
function performance( $visible = false ) {
	$stat = sprintf(  ' 请求%d 耗时%.3fs',
		get_num_queries(),
		timer_stop( 0, 3 ),
		memory_get_peak_usage() / 1024 / 1024
	);
	echo $visible ? $stat : "{$stat} " ;
}

//修改后台显示更新的代码
add_filter('pre_site_transient_update_core',    create_function('$a', "return null;")); // 关闭核心提示
//add_filter('pre_site_transient_update_plugins', create_function('$a', "return null;")); // 关闭插件提示
//add_filter('pre_site_transient_update_themes',  create_function('$a', "return null;")); // 关闭主题提示
//remove_action('admin_init', '_maybe_update_plugins'); // 禁止 WordPress 更新插件
remove_action('admin_init', '_maybe_update_core');    // 禁止 WordPress 检查更新
//remove_action('admin_init', '_maybe_update_themes');  // 禁止 WordPress 更新主题



/* 小工具插件结束*/
?>